<?php
declare (strict_types = 1);

namespace app\shop\controller;

use think\annotation\Route;
use think\annotation\route\Group;
use think\annotation\route\Middleware;
use app\common\service\ActivityService\ActivityService;
use app\common\service\GoodsService\GoodsService;
use app\BaseShopController;
use think\Request;
use app\Normal;

/**
 * @Group("Activity")
 * @Middleware({shopMiddileware::class})
 */
class Activity extends BaseShopController
{
     /**
     * 获取商品选择分页
     * @Route("getActivityGoodsListByPage",method="GET")
     * @return string
     */
    public function getActivityGoodsListByPage() {
        $param= $this->_all_data;
        $param['type']=1;
        $result = callApi(GoodsService::class, 'goodsList',$this->_all_data);
        return apiResponse($result);
    }
    /**
     * 获取数据表分页
     * @Route("getOrderActivityListByPage",method="GET")
     * @return string
     */
    public function getOrderActivityListByPage() {
        $param= $this->_all_data;
        $param['type']=1;
        $result = callApi(ActivityService::class, 'getActivityListByPage',$param);
        return apiResponse($result);
    }
    
    /**
     * 获取整单优惠详情
     * @Route("getOrderActivityDetail/:id",method="GET")
     * @return string
     */
    public function getOrderActivityDetail() {
        $param= $this->_all_data;
        $result = callApi(ActivityService::class, 'getActivityDetail',$param);
        return apiResponse($result);
    }
    
    /**
     * 新增整单活动
     * @Route("addOrderActivity",method="POST")
     * @return string
     */
    public function addOrderActivity() {
        $param= $this->_all_data;
        $param['type']=1;
        $param['op']='add';
        $result = callApi(ActivityService::class, 'addData',$param);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'新增整单促销活动','request_param'=> json_encode($param,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
    
    /**
     * 终止整单活动
     * @Route("stopOrderActivity",method="POST")
     * @return string
     */
    public function stopOrderActivity() {
        $param= $this->_all_data;
        $result = callApi(ActivityService::class, 'stopActivity',$param);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'停止整单促销活动id【'.$param['id'].'】','request_param'=> json_encode($param,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
    
    /**
     * 获取商品促销数据表分页
     * @Route("getGoodsActivityListByPage",method="GET")
     * @return string
     */
    public function getGoodsActivityListByPage() {
        $param= $this->_all_data;
        $param['type']=2;
        $result = callApi(ActivityService::class, 'getActivityListByPage',$param);
        return apiResponse($result);
    }
    
    /**
     * 获取商品促销优惠详情
     * @Route("getGoodsActivityDetail/:id",method="GET")
     * @return string
     */
    public function getGoodsActivityDetail() {
        $param= $this->_all_data;
        $param['op']='detail';
        $result = callApi(ActivityService::class, 'getActivityDetail',$param);
        return apiResponse($result);
    }
    
    /**
     * 新增商品促销活动
     * @Route("addGoodsActivity",method="POST")
     * @return string
     */
    public function addGoodsActivity() {
        $param= $this->_all_data;
        $param['type']=2;
        $param['op']='add';
        $result = callApi(ActivityService::class, 'addData',$param);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'新增商品促销活动','request_param'=> json_encode($param,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
    
    /**
     * 终止商品活动
     * @Route("stopGoodsActivity",method="POST")
     * @return string
     */
    public function stopGoodsActivity() {
        $param= $this->_all_data;
        $result = callApi(ActivityService::class, 'stopActivity',$param);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'停止商品促销活动id【'.$param['id'].'】','request_param'=> json_encode($param,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
    /**
     * 获取秒杀数据表分页
     * @Route("getSeckillActivityListByPage",method="GET")
     * @return string
     */
    public function getSeckillActivityListByPage() {
        $param= $this->_all_data;
        $param['type']=3;
        $result = callApi(ActivityService::class, 'getActivityListByPage',$param);
        return apiResponse($result);
    }
    
    /**
     * 获取秒杀详情
     * @Route("getSeckillActivityDetail/:id",method="GET")
     * @return string
     */
    public function getSeckillActivityDetail() {
        $param= $this->_all_data;
        $param['op']='detail';
        $result = callApi(ActivityService::class, 'getActivityDetail',$param);
        return apiResponse($result);
    }
    
    /**
     * 新增秒杀活动
     * @Route("addSeckillActivity",method="POST")
     * @return string
     */
    public function addSeckillActivity() {
        $param= $this->_all_data;
        $param['type']=3;
        $param['op']='add';
        $param['rule_type']=0;
        $param['unit_type']=0;
        $param['sync_online']=1;
        $result = callApi(ActivityService::class, 'addData',$param);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'新增秒杀活动','request_param'=> json_encode($param,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
    
    /**
     * 终止秒杀活动
     * @Route("stopSeckillActivity",method="POST")
     * @return string
     */
    public function stopSeckillActivity() {
        $param= $this->_all_data;
        $result = callApi(ActivityService::class, 'stopActivity',$param);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'停止秒杀活动id【'.$param['id'].'】','request_param'=> json_encode($param,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
    
    /**
     * 获取拼团数据表分页
     * @Route("getBookActivityListByPage",method="GET")
     * @return string
     */
    public function getBookActivityListByPage() {
        $param= $this->_all_data;
        $param['type']=4;
        $result = callApi(ActivityService::class, 'getActivityListByPage',$param);
        return apiResponse($result);
    }
    
    /**
     * 获取拼团详情
     * @Route("getBookActivityDetail/:id",method="GET")
     * @return string
     */
    public function getBookActivityDetail() {
        $param= $this->_all_data;
        $param['op']='detail';
        $result = callApi(ActivityService::class, 'getActivityDetail',$param);
        return apiResponse($result);
    }
    
    /**
     * 新增拼团活动
     * @Route("addBookActivity",method="POST")
     * @return string
     */
    public function addBookActivity() {
        $param= $this->_all_data;
        $param['type']=4;
        $param['op']='add';
        $param['rule_type']=0;
        $param['unit_type']=0;
        $param['sync_online']=1;
        $result = callApi(ActivityService::class, 'addData',$param);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'新增拼团活动','request_param'=> json_encode($param,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
    
    /**
     * 终止拼团活动
     * @Route("stopSeckillActivity",method="POST")
     * @return string
     */
    public function stopBookActivity() {
        $param= $this->_all_data;
        $result = callApi(ActivityService::class, 'stopActivity',$param);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'停止拼团活动id【'.$param['id'].'】','request_param'=> json_encode($param,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
    
    /**
     * 根据活动获取参与门店列表
     * @Route("getActivityStore/:activity_id",method="GET")
     * @return string
     */
    public function getActivityStore() {
        $param= $this->_all_data;
        $result = callApi(ActivityService::class, 'getActivityStoreByPage',$param);
        return apiResponse($result);
    }
}